/*
 * Copyright 2014 JootMir Project
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Support: http://www.jootmir.org
 */
package org.jootmir.client.game;

import javax.swing.JOptionPane;

import org.jootmir.client.core.Application;
import org.jootmir.client.core.ApplicationListener;
import org.jootmir.client.core.font.AWTFont;
import org.jootmir.client.core.font.Font;
import org.jootmir.client.core.font.FontLoadProgressChangedEventListener;

/**
 * 测试文字绘制
 * 
 * @author ShawRyan
 */
public class FontTest implements ApplicationListener {
	
	private Font font = new AWTFont("宋体", java.awt.Font.PLAIN, 28);
	
	public void create() {
		// 加载字体
		((AWTFont)font).loadCharacters(new FontLoadProgressChangedEventListener() {
			
			@Override
			public void progressChange(float progress) {
				//System.out.println(progress);
				Application.get().setTitle(progress * 100 + "%");
			}
		});
	}

	public void render() {
		// 绘制文字
		if(((AWTFont)font).isReadyForUse())
			font.drawString(0, 0, "将唐传奇");
	}

	public void dispose() {
		
	}

	public boolean isRequestExit() {
		return false;
	}

	public boolean acceptCloseEvent() {
		// FIXME 非awt下不是modal
		int res = JOptionPane.showConfirmDialog(null, "确认退出？", "退出游戏",
				JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
		if (res == JOptionPane.YES_OPTION)
			return true;
		else if (res == JOptionPane.NO_OPTION)
			return false;
		return true;
	}

}
